package dao;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import Entity.RolEntity;
import Utils.HibernateUtil;
import dto.RolDTO;

public class RolDAO {
	
	private static RolDAO instance;
	private static SessionFactory sf;
	
	public static RolDAO getInstance ()
	{
		if (instance == null)
		{
			sf = HibernateUtil.getSessionFactory();
			instance = new RolDAO();
		}
		return instance;
	}
	
	public RolDTO ObtenerRol (String nombre)
	{
		RolDTO rol = new RolDTO();
		RolEntity aux; 
		Session session = sf.openSession();
		Query q = session.createQuery("from RolEntity where nombre = ?").setString(0, nombre);
		aux = (RolEntity) q.uniqueResult();
		rol.setNombre(aux.getNombre());
		rol.setNumero(aux.getNumero());
		return rol;
	}

}
